// pages/allStoreShop/allStoreShop.js
const app = getApp()
var utils = require('../../utils/util.js')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        currentPage: 1
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.storeList(this.data.currentPage);
    },
    //店铺列表
    storeList: function(currentPage) {
        var that = this;
        console.log(that.data.schoolid)
        utils.http("/api/v1/store/store_list", {
            latitude: wx.getStorageSync("localhost").latitude,
            longitude: wx.getStorageSync("localhost").longitude,
            school_id: wx.getStorageSync("schoolInfo").schoolid,
            page: currentPage
        }, function(res) {
            if (res.state == 1) {
                var allpost = that.data.store;
                if (allpost == undefined) {
                    allpost = [];
                }
                for (var i in res.datas) {
                    allpost.push(res.datas[i])
                }
                if (res.datas.length < 10) {
                    that.setData({
                        tishi_title: '已加载全部',
                    });
                } else {
                    that.setData({
                        tishi_title: '加载更多',
                    });
                }
                that.setData({
                    store: allpost,
                    ready: res.datas.length == 0 ? 1 : 2,
                })

            } else {
                utils.message(res.datas)
            }
        })
    },
	//进入店铺
	onStoreShopTap: function (e) {
		console.log(e)
		wx.navigateTo({
			url: '../storeShop/storeShop?id=' + e.currentTarget.dataset.storeid
		})
	},
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {
        this.setData({
            store: []
        })
        this.storeList(1);
        wx.stopPullDownRefresh();
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
        var that = this;
        if (that.data.ready == 2) {
            var page = that.data.currentPage + 1
            that.setData({
                currentPage: page,
            })
            this.storeList(page);
        }

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})